﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Text;

namespace Lawyer.Web.Admin
{
    public partial class admin_postupdate : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            string ID = Initial();
            if (!IsPostBack)
            {
                BindData(ID);
            }

        }

        private string Initial()
        {
            string ID=Request["ID"] == null ? null : Request["ID"].ToString();
            if (ID == null)
            {
                Response.Redirect("admin_postadd.aspx");
                return null;
            }
            else
            {
                return ID;
            }
        }

        private void BindData(string id)
        {
            Lawyer.BLL.PostInfo model = new Lawyer.BLL.PostInfo();
            Lawyer.Model.PostInfo post = model.GetModel(id);
            txtTile.Text = post.Tile;
            txtDetail.Text = post.Detail;

        }



        protected void btnPostUpdate_Click(object sender, EventArgs e)
        {
            string ID = Initial();
            Lawyer.BLL.PostInfo modelBll = new Lawyer.BLL.PostInfo();

            string strErr = "";

            if (this.txtTile.Text.Trim().Length == 0)
            {
                strErr += "Tile不能为空！\\n";
            }
            if (this.txtDetail.Text.Trim().Length == 0)
            {
                strErr += "Detail不能为空！\\n";
            }



            string Tile = this.txtTile.Text;
            string Detail = this.txtDetail.Text;
            string UpdatedBy = Session["UserID"].ToString(); ;
            DateTime UpdatedDate = DateTime.Now;

            Lawyer.Model.PostInfo model = modelBll.GetModel(ID);

            model.Tile = Tile;
            model.Detail = Detail;

            model.UpdatedBy = UpdatedBy;
            model.UpdatedDate = UpdatedDate;

            Lawyer.BLL.PostInfo bll = new Lawyer.BLL.PostInfo();
            if (bll.Update(model))
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "Update Success！", "admin_postupdate.aspx?id=" + model.PostID);
            }
            else {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "Update Failed！", "admin_postupdate.aspx?id=" + model.PostID);
            }
        }

    }
}
